<?php


namespace app\common\controller;


use app\common\model\User;
use tegic\qiniu\Qiniu;
use think\Exception;
use think\App;
use think\facade\Env;

class UserController extends BaseController
{
    static $payment;
    static $order;
    static $good;
    static $response;
    /** @var  User $user */
    static $user;

    function __construct(App $app = null)
    {
        parent::__construct($app);
        self::checkUser();
    }
    function getUid(){
        return User::getUid();
    }

    function getServerId(){
       $user = $this->getUser();
        $server = $user->getServer();
        if($server){
            return $server->id;
        }
        return 0;
    }

    function getEmployId(){
        $user = $this->getUser();
        $employ = $user->getEmploy();
        if($employ){
            return $employ->id;
        }
        return 0;
    }

    /**
     * @return array|null|\PDOStatement|string|\app\common\model\User
     */
    function getUser(){
        if(!self::$user){
            self::$user = User::getUser();
        }
        return self::$user;
    }

    function checkUser(){
        $user = $this->getUser();
        if(empty($user)){
            $this->nologin();
        }
    }

    public  function nologin(){
        $this->result_error("请登录",-10000);
    }



    public function upload(){
        try{
            $qiniu = new Qiniu();
            $result = $qiniu->upload();
            $url = Env::get("qiniu_domain").$result;
            $this->result_success($url);
        }catch (Exception $e){
            $this->result_error($e->getMessage());
        }
    }


}